<template>
  <div class="container" ref="container">
    <!-- 顶部 -->
    <div class="task_header">
      <div class="top_title">
        <div class="top_title_back" @click="onClickLeft">
          <i class="iconfont icon-back"></i>
        </div>
        <div class="top_title_val">{{ $route.meta.title }}</div>
      </div>
    </div>
    <div class="info">

      <van-radio-group v-model="requestParams.type" direction="horizontal" style="font-size: 12px">
        <van-radio name="1" shape="square">手机号查询</van-radio>
        <van-radio name="2" shape="square">车牌号查询</van-radio>
        <van-radio name="3" shape="square">车架号查询</van-radio>
      </van-radio-group>

      <input v-model="requestParams.queryText" class="info_input" :placeholder="placeholder" @blur="onBlur" @input="onInput" />


      <div class="searchBtn" @click="handleSubmit">查询</div>
      <div class="tips">请选择手机号、车牌号或车架号其中一个输入对应的信息进行查询</div>

    </div>
  </div>
</template>

<script>
import { Dialog, Toast } from 'vant'
import vipInfoApi from '@/api/vipInfoApi'

export default {
  name: 'bindCarIndex',
  components: { Toast, Dialog },
  data() {
    return {
      requestParams: {
        type: '1', //查询类型，int，必填（1=手机号；2=车牌号；3=车架号）
        queryText: '',
      },
      placeholder: '请输入完整手机号'
    }
  },
  watch: {
    requestParams: {
      handler: function (val, oldVal) {
        const type = val.type
        switch (type) {
          case '1':
            this.placeholder = '请输入完整手机号'
            break
          case '2':
            this.placeholder = '请输入完整车牌号'
            break
          case '3':
            this.placeholder = '请输入完整车架号'
            break
          default:
            this.placeholder = ''
            break
        }
      },
      deep: true,
      immediate: false,
    },
  },

  mounted() {},

  methods: {
    onClickLeft() {
      this.$router.go(-1)
    },
    toUpperCase(str) {
      return str.replace(/[a-z]/g, function (match) {
        return match.toUpperCase()
      })
    },
    onBlur() {
      if (this.requestParams.type == '2' ||this.requestParams.type == '3')
      this.requestParams.queryText = this.toUpperCase(this.requestParams.queryText)
    },
    onInput() {
      if (this.requestParams.type == '1' && this.requestParams.queryText.length > 11) {
        this.requestParams.queryText = this.requestParams.queryText.slice(0, 11)
      }
    },
    handleSubmit() {
      if (!this.requestParams.type) {
        Toast('请选择查询类型进行查询')
        return
      }
      if (!this.requestParams.queryText) {
        Toast('请输入相关信息进行查询')
        return
      }
      Toast.loading('查询中...')
      this.$router.push({ path: '/bindCarDetail', query: { params: this.requestParams } })

    },
  },
}
</script>

<style lang="less" scoped="">
.task_header {
  background: url('~@/assets/images/title_bg.png') no-repeat center;
  font-size: 0.24rem;
  height: 45px;
  background-size: 100% 100%;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 9;

  .top_title {
    position: relative;
    width: 100%;
    height: 50px;

    .top_title_back {
      position: absolute;
      left: 10px;
      line-height: 50px;
      color: #fff;
    }

    .top_title_val {
      text-align: center;
      line-height: 50px;
      color: #fff;
      font-weight: bold;
      font-size: 16px;
    }
    .task_transbox {
      position: absolute;
      right: 10px;
      top: 20px;
      color: #fff;
      z-index: 10;
      font-weight: 400;
      font-size: 12px;
      text-align: center;
      .task_trans {
        width: 24px;
        display: block;
        margin: auto;
      }
    }
  }

  .task_header_data {
    .task_header_date {
      margin-bottom: 10px;
      display: flex;
      align-items: center;

      .task_header_date_w {
        width: 12.5%;
      }

      .task_header_date_item {
        width: 12.5%;
        text-align: center;
        color: #fff;
        font-size: 14px;
      }
    }

    .task_header_followData {
      display: flex;
      align-items: center;
      color: #fff;
      margin-bottom: 10px;

      .task_header_followData_tt {
        width: 12.5%;
        text-align: center;
      }

      .task_header_followData_item {
        width: 12.5%;
        text-align: center;
        font-size: 12px;
        font-weight: bold;
      }
    }
  }
}
.info {
  padding-top: 90px;
  width: 300px;
  margin: auto;
  .info_input {
    padding-left: 10px;
    padding-right: 10px;
    background: none;
    border: 1px solid #3975c6;
    width: 280px;
    line-height: 32px;
    margin-top: 10px;
    font-size: 12px;
  }

  .searchBtn {
    width: 300px;
    margin: auto;
    text-align: center;
    font-size: 14px;
    background: linear-gradient(316deg, #3975c6 0%, #71a4ea 100%);
    color: #fff;
    padding: 12px 0rem;
    border-radius: 50px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 50px;
  }
  .tips {
    text-align: left;
    font-size: 16px;
    color: #999;
    margin-top: 40px;
  }
}
::-webkit-input-placeholder {
  color: #a3a3a3;
}

.mb0 {
  margin-bottom: 0 !important;
}
.van-radio-group--horizontal {
  justify-content: space-between;
}
.van-radio--horizontal {
  margin-right: unset;
}
.van-radio__label {
  margin-left: 4px;
}
</style>
